// Jake

void unable(NPC@ npc){
	npc.addText("Are you lacking mesos? Check and see if you have an empty slot in your ETC inventory or not.");
	npc.sendNext();
	npc.end();
}

void npc(Player @player, NPC @npc) {
	int state = npc.getState();
	int type = npc.getSelected();
	npc.setVariable("type", type);
	if(state > 1 && npc.getSelected() == NO){
		npc.addText("You can enter the premises once you have bought the ticket. I heard there are strange devices in there everywhere but in the end, rare precious items await you. So let me know if you ever decide to change your mind.");
		npc.sendOK();
		npc.end();
	}
	if((state == 2 && player.getMesos() < 500 && npc.getSelected() == YES) || (state == 3 && player.getMesos() < 1200 && npc.getSelected() == YES) || (state == 4 && player.getMesos() < 2000 && npc.getSelected() == YES)){
		unable(npc);
	}
	if(state == 0){
		if(player.getLevel() >= 20){
			npc.addText("You must purchase the ticket to enter. Once you have made the purchase, you can enter through the ticket gate on the right. What would you like to buy?\r\n#b#L0#construction site B1#l#k\r\n");
			if(player.getLevel() >= 30){
				npc.addText("#b#L1#construction site B2#l#k\r\n");
				if(player.getLevel() >= 40){
					npc.addText("#b#L2#construction site B3#l#k");
				}
			}
			npc.sendSimple();
		}
		else{
			npc.addText("You can enter the premises once you have bought the ticket; however it doesn't seem like you can enter here. There are foreign devices underground that may be too much for you to handle, so please train yourself, be prepared, and then come back.");
			npc.sendOK();
			npc.end();
		}
	}
	else if(state == 1){
		if(type == 0){
			npc.addText("Will you purchase the ticket to #bconstruction site B1#k? It'll cost you 500 mesos. Before making the purchase, please make sure you have an empty slot in your etc. inventory.");
			npc.sendYesNo();
		}
		else if(type == 1){
			npc.addText("Will you purchase the ticket to #bconstruction site B2#k? It'll cost you 1200 mesos. Before making the purchase, please make sure you have an empty slot in your etc. inventory.");
			npc.sendYesNo();
			npc.setState(2);
		}
		else if(type == 2){
			npc.addText("Will you purchase the ticket to #bconstruction syte B3#k? It'll cost you 2000 mesos. Before making the purchase, please make sure you have an empty slot in your etc. inventory.");
			npc.sendYesNo();
			npc.setState(3);
		}
	}
	else if(state == 2){
		if(npc.getSelected() == YES){
			if(player.checkSlot(ETC)){
				player.giveMesos(-500);
				player.giveItem(4031036, 1);
				npc.addText("You can insert the ticket in the Ticket Gate. I heard Area 1 has some precious items available but with so many traps all over the place most come back out early. Wishing you the best of luck.");
				npc.sendOK();
				npc.end();
			}
			else{
				unable(npc);
			}
		}
	}					
	else if(state == 3){
		if(npc.getSelected() == YES){
			if(player.checkSlot(ETC)){
				player.giveMesos(-1200);
				player.giveItem(4031037, 1);
				npc.addText("You can insert the ticket in the Ticket Gate. I heard Area 2 has rare, precious items available but with so many traps all over the place most come back out early. Wishing you the best of luck.");
				npc.sendOK();
				npc.end();
			}
			else{
				unable(npc);
			}
		}
	}
	else if(state == 4){
		if(npc.getSelected() == YES){
			if(player.checkSlot(ETC)){
				player.giveMesos(-2000);
				player.giveItem(4031038, 1);
				npc.addText("You can insert the ticket in the Ticket Gate. I heard Area 3 has very rare, very precious items available but with so many traps all over the place most come back out early. Wishing you the best of luck.");
				npc.sendOK();
				npc.end();
			}
			else{
				unable(npc);
			}
		}
	}
}